<template>
    <div>
        <el-row v-if="name!=''">
            <el-col :span="3">欢迎您：</el-col>
            <el-col :span="4">{{name}}!</el-col>
            <a @click="loginout()">注销</a>
        </el-row>
        <el-row v-else>
            <el-col :span="3">您还未登录！</el-col>
        </el-row>

    </div>
</template>

<script>
    export default {
        name: 'HelloWorld',
        data() {
            return {
                msg: "",
                name: ""
            }
        },
        created() {
            this.checkLogin()
        },
        methods: {
            checkLogin() {
                var user = JSON.parse(localStorage.getItem("user"));
                console.log(user)
                if (user) {
                    this.name = user
                }
            },
            loginout() {
                localStorage.removeItem("user")
                this.$message({
                    message: '注销成功！',
                    type: 'success'
                });
                this.$router.push({
                    path: "/"
                })
            }
        }
    }
</script>

<style>
    .el-col {
        font-size: 20px;
    }
</style>
